package mysql

import (
	"gorm.io/gorm"
	"rent-ease/rentrpc/rentrpc"
)

type User struct {
	gorm.Model
	UserName string `gorm:"type:varchar(50);not null;comment:'用户名'"`
}

type Rent struct {
	gorm.Model
	Name    string  `gorm:"type:varchar(50);not null;comment:'名称'"`
	Address string  `gorm:"type:varchar(255);not null;comment:'地区'"`
	Price   float64 `gorm:"type:decimal(10,2);not null;comment:'价格'"`
}

func (r *Rent) RentFindById(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(r).Error
}

func RentList(db *gorm.DB) ([]*rentrpc.RentList, error) {
	var list []*rentrpc.RentList

	err2 := db.Debug().Model(&Rent{}).
		Select(
			"id as rent_id",
			"name",
			"address",
			"price").
		Find(&list).
		Error
	return list, err2
}
